package com.comtime.mybox;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.comtime.smartbox.BaseActivity;
import com.comtime.smartbox.HBApplication;
import com.comtime.smartkilimanjaro.R;
import com.comtime.view.MyDialog;
import com.sina.weibo.sdk.api.share.Base;

public class AddFringerActivity extends BaseActivity{
	HBApplication application;
	
	
	public static final String Action_RegisterFailed=AddFringerActivity.class.getName()+"Action_RegisterFailed";
	public static final String Action_RegisterStartedSuccess=AddFringerActivity.class.getName()+"Action_RegisterStartedSuccess";
	public static final String Action_Step_1_Complete=AddFringerActivity.class.getName()+"Action_Step_1_Complete";
	public static final String Action_Step_2_Complete=AddFringerActivity.class.getName()+"Action_Step_2_Complete";
	public static final String Action_Step_3_Complete=AddFringerActivity.class.getName()+"Action_Step_3_Complete";
	public static final String Extra_ID=AddFringerActivity.class.getName()+"Extra_ID";
	

	EditText edt_name;
	TextView tv_content;
	ImageView imageView;
	RelativeLayout relate_finger,relate_ok;
	LinearLayout line_over;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		application = (HBApplication) getApplication();
		setContentView(R.layout.activity_set_addfinger);
		init();
		if( application.swDevicesList.get(0).isConnected()){
			 application.swDevicesList.get(0).sendRegisterlock();
		}
		IntentFilter intentFilter=new IntentFilter();
		intentFilter.addAction(Action_RegisterFailed);
		intentFilter.addAction(Action_RegisterStartedSuccess);
		intentFilter.addAction(Action_Step_1_Complete);
		intentFilter.addAction(Action_Step_2_Complete);
		intentFilter.addAction(Action_Step_3_Complete);
		
		registerReceiver(new BroadcastReceiver() {
			
			@Override
			public void onReceive(Context arg0, Intent intent) {
				// TODO Auto-generated method stub
				String action=intent.getAction();
				if(action.equals(Action_RegisterFailed)){
					showFailed();
				}else if(action.equals(Action_RegisterStartedSuccess)){
					imageView.setImageResource(R.drawable.icon_setup_finger_first);
					tv_content.setText(getText(R.string.fingerprint_content_two).toString());
				} else if(action.equals(Action_Step_1_Complete)){
					imageView.setImageResource(R.drawable.icon_setup_finger_second);
					tv_content.setText(getText(R.string.fingerprint_content_two).toString());
				}else if(action.equals(Action_Step_2_Complete)){
					imageView.setImageResource(R.drawable.icon_setup_finger_third);
					tv_content.setText(getText(R.string.fingerprint_content_two).toString());
				}else if(action.equals(Action_Step_3_Complete)){
					
					imageView.setImageResource(R.drawable.icon_setup_finger_last);
					tv_content.setText(getText(R.string.fingerprint_add_success).toString());
					line_over.setVisibility(View.VISIBLE);
				}
				
			}
		}, intentFilter);
	}
	
	
	protected void showFailed() {
		 final MyDialog dialog=new MyDialog(this);
		 
		 dialog.setTitle(getString(R.string.fingerprint_register_failed));
		 dialog.setLeftButtonText(getString(R.string.ok));
		 dialog.getLeftButton().setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				dialog.dismiss();
				AddFringerActivity.this.finish();
			}
		});
		dialog.show();
	}


	int step=0;
	void init(){
		relate_finger=(RelativeLayout) findViewById(R.id.relate_finger);
		tv_content=(TextView) findViewById(R.id.tv_content);
		line_over=(LinearLayout) findViewById(R.id.relate_finger_over);
		relate_ok=(RelativeLayout) findViewById(R.id.relate_ok);
		edt_name=(EditText) findViewById(R.id.edt_name);
		imageView=(ImageView) findViewById(R.id.imageview);
		 
		
		relate_ok.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				
				
			}
		});
	}
	
	public void BackAction(View v) {
		this.finish();
		overridePendingTransition(R.anim.enter_left, R.anim.exit_right);
	}

	
	
}
